#include "Ant.h"

Ant::Ant(CGrid& ant_grid):grid(ant_grid)
{
	this->direction = Up;
	this->position[0] = grid.size/2;
	this->position[1] = grid.size/2;
}

Ant::~Ant(void)
{
}

int Ant::Ant_step()
{
	char state = grid.Get_state(position);
	grid.Flip_state(position);
	if (state == 0)
		switch(direction)
		{
			case Up:
				position[0] += 1;
				direction = Right;
				break;
			case Right:
				position[1] += 1;
				direction = Down;
				break;
			case Down:
				position[0] -= 1;
				direction = Left;
				break;
			case Left:
				position[1] -= 1;
				direction = Up;
				break;
		}
	else
		switch(direction)
		{
			case Up:
				position[0] -= 1;
				direction = Left;
				break;
			case Right:
				position[1] -= 1;
				direction = Up;
				break;
			case Down:
				position[0] += 1;
				direction = Right;
				break;
			case Left:
				position[1] += 1;
				direction = Down;
				break;
		}
	return 0;
}